package com.baomidou.ant.controller;

import com.baomidou.ant.common.Result;
import com.baomidou.ant.entity.PointsStore;
import com.baomidou.ant.entity.UserBag;
import com.baomidou.ant.service.IPointsStoreService;
import com.baomidou.ant.service.IUserBagService;
import com.baomidou.ant.vo.Response.ResponseGoodsInfoVo;
import com.baomidou.ant.vo.Response.ResponseMyBagVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/userBag")
public class UserBagController {
    @Autowired
    private IUserBagService userBagService;
    @Autowired
    private IPointsStoreService pointsStoreService;

    //背包生成
    @GetMapping("/myBag/{userId}")
    public Result myBag(@PathVariable Integer userId){
        QueryWrapper<UserBag> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        UserBag userBag=userBagService.getOne(queryWrapper);
        ResponseMyBagVo responseMyBagVo=new ResponseMyBagVo();
        responseMyBagVo.setBagLevel(userBag.getBagLevel());
        responseMyBagVo.setTotalAmount(userBag.getTotalAmount());
        responseMyBagVo.setUsedAmount(userBag.getUsedAmount());
        return Result.getSuccess().setData(responseMyBagVo);
    }

    //背包内容物信息展示
    @GetMapping("/goodsInfo/{goodsId}")
    public Result goodsInfo(@PathVariable Integer goodsId){
        PointsStore goods=pointsStoreService.getById(goodsId);
        ResponseGoodsInfoVo responseGoodsInfoVo=new ResponseGoodsInfoVo();
        responseGoodsInfoVo.setGoodsDesc(goods.getGoodsDesc());
        responseGoodsInfoVo.setGoodsName(goods.getGoodsName());
        responseGoodsInfoVo.setGoodsType(goods.getGoodsType());
        return  Result.getSuccess().setData(responseGoodsInfoVo);
    }

}
